package com.ningxia.water.controller.auth;

import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.ningxia.water.entity.SysFrontendMenuTable;
import com.ningxia.water.reuslt.Result;
import com.ningxia.water.reuslt.ResultResponse;
import com.ningxia.water.service.SysFrontendMenuTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (SysFrontendMenuTable)表控制层
 */
@RestController
@RequestMapping("/menu")
@Api(tags = {"权限控制-前端菜单管理"})
public class SysFrontendMenuTableController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private SysFrontendMenuTableService sysFrontendMenuTableService;

    /**
     * 分页查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping("/getinfos")
    @ApiOperation(value = "所有菜单数据")
    public Result selectAll() {
        return ResultResponse.getSuccessResult(this.sysFrontendMenuTableService.getAllMenuList());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/getinfo/{id}")
    @ApiOperation(value = "通过id查询菜单")
    public Result selectOne(@PathVariable Serializable id) {
        return ResultResponse.getSuccessResult(this.sysFrontendMenuTableService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param sysFrontendMenuTable 实体对象
     * @return 新增结果
     */
    @PostMapping("/insertmenu")
    @ApiOperation(value = "新增菜单")
    public Result insert(@RequestBody SysFrontendMenuTable sysFrontendMenuTable) {
        boolean isSave = this.sysFrontendMenuTableService.save(sysFrontendMenuTable);
        if (isSave){
            return ResultResponse.getSuccessResult("添加成功");
        }else {
            return ResultResponse.getFailResult("添加失败");
        }

    }

    /**
     * 修改数据
     *
     * @param sysFrontendMenuTable 实体对象
     * @return 修改结果
     */
    @PutMapping("/updatemenu")
    @ApiOperation(value = "修改菜单")
    public Result update(@RequestBody SysFrontendMenuTable sysFrontendMenuTable) {
        boolean isUpdate = this.sysFrontendMenuTableService.updateById(sysFrontendMenuTable);
        if (isUpdate){
            return ResultResponse.getSuccessResult("修改成功");
        }else {
            return ResultResponse.getFailResult("修改失败");
        }

    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/deletemenu")
    @ApiOperation(value = "删除菜单")
    public Result delete(@RequestParam("idList") List<String> idList) {
        boolean isDelete = this.sysFrontendMenuTableService.removeByIds(idList);
        if (isDelete){
            return ResultResponse.getSuccessResult("删除成功");
        }else {
            return ResultResponse.getFailResult("删除失败");
        }

    }
}
